var person = [
	{ name: 'Bom', age: 12 },
	{ name: 'Jack', age: 10 },
	{ name: 'Bob', age: 22 },
	{ name: 'Ba', age: 5 },
	{ name: 'Tony', age: 25 },
]
// 定义sort比较函数
let compareFun = (m,n)=>{
    if(Object.prototype.toString.call(m) == '[object Object]'){
        m = m.name
        n = n.name
    }
    let a = m.substring(0,1)
    let b = n.substring(0,1)
    if(a < b){
        return -1
    }
    if(a > b){
        return 1
    }
    return compareFun(m.substring(1),n.substring(1))
}

person.sort(compareFun)

/**
 * 英语则是根据字母排序的,
 * 汉字根据汉字拼音来排序。
 *   a.localCompare(b) – 升序
 *   b.localCompare(a) – 降序
 */
person.sort(function(a, b) {
    return (a.name).localeCompare(b.name)
})
console.log(person);